<div class="asidetop">
    <ul class="tab_navs">
        <li>
            <a onclick="getRight('/Sucai/single');"  href="javascript:void(0)">添加单图文消息</a>
        </li>
        <li class="selected">
            <a onclick="getRight('/Sucai/double');" href="javascript:void(0)">添加多图文消息</a>
        </li>
         <li >
            <a onclick="getRight('/Sucai/text');" href="javascript:void(0)">添加文本消息</a>
        </li>
         <li >
            <a onclick="getRight('/Sucai/image');" href="javascript:void(0)">添加图片消息</a>
        </li>
        
    </ul>
</div>
<div style="padding:30px 20px 0">


    <div class="media_preview_area">
        <div class="appmsg multi editing">


            <div class="appmsg_content">  

                <div class="js_appmsg_item " id="info1">
                    <div class="appmsg_info">
                        <em class="appmsg_date"></em>
                    </div>
                    <textarea style="display: none;"></textarea>
                    <input type="hidden" style="display: none;" class="input_url"/>
                    <div class="cover_appmsg_item">
                        <h4 class="appmsg_title"><a href="javascript:void(0);">标题</a></h4>
                        <div class="appmsg_thumb_wrp">
                            <img src="" class="js_appmsg_thumb appmsg_thumb"><i class="appmsg_thumb default">封面图片</i>
                        </div>
                        <div class="appmsg_edit_mask">
                            <a href="javascript:;" class="icon18_common edit_gray js_edit">编辑</a>
                        </div>
                    </div>
                </div>

                <div class="appmsg_item js_appmsg_item" id="info2">
                    <textarea style="display: none;"></textarea>
                    <input type="hidden" style="display: none;" class="input_url"/>
                    <img src="" class="js_appmsg_thumb appmsg_thumb"><i class="appmsg_thumb default">缩略图</i>
                    <h4 class="appmsg_title"><a href="javascript:void(0);" >标题</a></h4>
                    <div class="appmsg_edit_mask">
                        <a href="javascript:void(0);" class="icon18_common edit_gray js_edit">编辑</a>
                        <a href="javascript:void(0);" class="icon18_common del_gray js_del">删除</a>
                    </div>
                </div>

            </div>


            <div class="appmsg_add">
                <a href="javascript:void(0);">&nbsp;<i class="icon24_common add_gray">增加一条</i></a>
            </div>
        </div>
    </div>



    <div class="media_edit_area">
        <input type="hidden" id="obj" value="info1" />
        <div id="js_appmsg_editor">
            <div class="appmsg_editor" style="margin-top: 0px;"> 
                <div class="inner">
                    <div class="appmsg_edit_item">
                        <label class="frm_label">标题</label>
                        <span class="frm_input_box"><input type="text" class="frm_input js_title"></span>
                    </div>
                    
<!--                    <div class="appmsg_edit_item">
                        <label class="frm_label">链接</label>
                        <span class="frm_input_box"><input type="text" class="frm_input js_url"></span>
                    </div>-->
                    
                    <div class="appmsg_edit_item">
                        <label class="frm_label">
                            <strong class="title">封面</strong>
                            <p class="js_cover_tip tips r">大图片建议尺寸：360像素 * 200像素</p>
                        </label>

                        <input id="file_upload" name="pib" type="file">
                    </div>

                    <p>
                        <a href="javascript:void(0);" class="js_addDesc" style="display: none;">添加摘要</a>
                    </p>
                    <div class="js_desc_area dn appmsg_edit_item" style="display: none;">
                        <label class="frm_label">摘要</label>
                        <span class="frm_textarea_box">
                            <textarea class="js_desc frm_textarea">
                            </textarea>
                        </span>
                    </div>
                    <div class="appmsg_edit_item content_edit" >
                        <a class="icon16_common close jsClose" href="javascript:void(0);">关闭</a>
                        <label class="frm_label">
                            <strong class="title">正文</strong>
                        </label>
                        <script id="editor" type="text/plain" name="content" style="width:380px;height:360px;"></script>


                    </div>
                    <p>
                        <a  href="javascript:void(0);" class="js_addURL">添加原文链接</a>
                    </p>
<!--                    <div class="js_url_area dn appmsg_edit_item" style="display: none;">
                        <label class="frm_label">原文链接 </label>
                        <span class="frm_input_box"><input type="text" class="js_url frm_input"></span>
                    </div>-->
                </div><i class="arrow arrow_out" style="margin-top: 0px;"></i>
                <i class="arrow arrow_in" style="margin-top: 0px;"></i>
                <div class="mask" style="display: none;">
                </div>
            </div>
        </div>

    </div>


    <div class="tool_area">
        <div class="tool_bar border tc">
            <!--<span class="btn btn_input btn_default">
                <button>预览 </button>
            </span>-->
            <span class="btn btn_input btn_primary" id="submit_news">
                <button>保存</button>
            </span>
        </div>
    </div>


</div>

<script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/ueditor/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript">
    $(function() {
        
        var ue = UE.getEditor('editor');
        
        ue.addListener("contentChange",function(){
            var areaTag = $("#obj").val();
            if(areaTag==""){
                //alert("请选择编辑区域！");
            }else{
                var content = ue.getContent();
                if(content != ""){
                    $("#"+areaTag).children("textarea").html(content);
                }
                    
            }
               
                
        });
                
                
                
        $(".appmsg_add").click(function(){
            
            var num = $(".js_appmsg_item").size();
            if(num >= 5){
                alert("最多发布5条！");
                    
            }else{
                num++;
                var add_html = '<div class="appmsg_item js_appmsg_item" id="info'+num+'"><textarea style="display: none;"></textarea><input type="hidden" style="display: none;" class="input_url"/><img src="" class="js_appmsg_thumb appmsg_thumb"><i class="appmsg_thumb default">缩略图</i><h4 class="appmsg_title"><a href="javascript:void(0);" >标题</a></h4><div class="appmsg_edit_mask"><a href="javascript:void(0);" class="icon18_common edit_gray js_edit">编辑</a><a href="javascript:void(0);" class="icon18_common del_gray js_del">删除</a></div></div>';
                $(".appmsg_content").append(add_html);                    
            }
                
        });
        
        $(".js_del").live("click",function(){
            var num = $(".js_appmsg_item").size();
            if(num <=2){
                alert("至少发布2条！");
            }else{
                $(this).parents(".js_appmsg_item").remove();
            
            }
        });
        
    
        $(".js_edit").live("click",function(){
        
            $(".js_title").val("");
            $(".js_url").val("");
            ue.setContent("");
            $("#obj").val($(this).parents(".js_appmsg_item").attr("id"));
        
            var html = $(this).parents(".js_appmsg_item").children("textarea").html();
            var input_url =$(this).parents(".js_appmsg_item").children(".input_url").val();
            $(".js_url").val(input_url);
            if(html != ""){
                ue.setContent(html);
            }
        
            var tag =$(this).parents(".js_appmsg_item").children('h4').html();
            if(tag+'|' =='undefined|'){
                var temp_title = $(this).parents(".js_appmsg_item").children('.cover_appmsg_item').children('h4').html();
            }else{
                var temp_title = $(this).parents(".js_appmsg_item").children('h4').html();
            }
            if(temp_title !='<a href="javascript:void(0);">标题</a>'){
                $(".js_title").val(temp_title);
            
            }
        
        
        });
        
        $('.js_title').live('keyup',function(){
             
            var areaTag = $("#obj").val();
             
            if(areaTag ==""){
                 
                alert("请选择编辑区域！");
                $(this).val("");
                 
            }else{
                var tag =$("#"+areaTag).children("h4").html();
                 
                if(tag+"|" =="undefined|"){
                    $("#"+areaTag).children(".cover_appmsg_item").children("h4").html($(this).val());
                }else{
                    $("#"+areaTag).children("h4").html($(this).val());
                }
                
                 
            }
      
        });
   
           $('.js_url').live('keyup',function(){
             
            var areaTag = $("#obj").val();
             
            if(areaTag ==""){
                 
                alert("请选择编辑区域！");
                $(this).val("");
                 
            }else{
                    $("#"+areaTag).children(".input_url").val($(this).val());     
            }
      
        });
        
        $('#submit_news').live('click',function(){
            var title_Arr = new Array();
            var content_Arr= new Array();
            var pic_Arr = new Array();
            var url_Arr = new Array();
            $('.js_appmsg_item').each(function(i){
                var tag =$(this).children('h4').html();
                 
                if(tag+'|' =='undefined|'){
                    var temp_title = $(this).children('.cover_appmsg_item').children('h4').html();
                    var temp_pic = $(this).children(".cover_appmsg_item").children(".appmsg_thumb_wrp").children('.js_appmsg_thumb').attr('src');
                }else{
                    var temp_title =$(this).children('h4').html();
                    var temp_pic =$(this).children('.js_appmsg_thumb').attr('src');
                }
                var temp_content = $(this).children('textarea').html();
                var temp_url = $(this).children('.input_url').val();
                     
                    
                title_Arr.push(temp_title);
                content_Arr.push(temp_content);
                pic_Arr.push(temp_pic);
                url_Arr.push(temp_url);
                    
                    
            });
            
            $.post('/Sucai/add_double',{title:title_Arr,content:content_Arr,pic:pic_Arr,url:url_Arr},function(){
                getRight('/Sucai/double');
            });
            
        });
        
        $('#postfrom').ajaxForm({
            beforeSubmit:function(){
                $('.js_desc').val($.trim($('.js_desc').val()));
                if (!$('.js_title').val()) {
                    successBox('error','请填写标题！');
                    return false
                }
                if (!$('#post_pic').val()) {
                    successBox('error','请上传图片！');
                    return false
                }
                if (!$('.js_desc').val()) {
                    successBox('error','请填写摘要！');
                    return false
                }
                if (!UE.getEditor('editor').getContent()) {
                    successBox('error','请填写正文！');
                    return false
                }
                $('#submits').attr('disabled','true');
                return true;
            },
            success:function(){
                successBox('success','上传成功！',1000);
                getRight('/Sucai/single');
            },
            dataType: 'json'
        });
			
        $('#file_upload').uploadify({
            'swf'      : '/Public/js/uploadify/uploadify.swf',
            'uploader' : '/Public/js/uploadify/uploadify.php',
            'buttonText':'上传',
            'height':'25',
            'width':'60',
            'queueSizeLimit' : 1,
            'onUploadSuccess' : function(file, data, response) {
                data =  $.trim(data);
                if(data!='error'){
                    var areaTag = $("#obj").val();
                    
                    
                    var tag =$("#"+areaTag).children("h4").html();
                    if(tag+"|" =="undefined|"){
                        $("#"+areaTag).children(".cover_appmsg_item").children(".appmsg_thumb_wrp").children('.js_appmsg_thumb').attr('src',data).show();
                    }else{
                        $("#"+areaTag).children('.js_appmsg_thumb').attr('src',data).show();
                        $("#"+areaTag).children(".default").remove();
                    }
                }
            },
        });
    });

</script>